layui.config({
    base: basePath,
    version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui', 'ClipboardJS'], function (exports) {
    winui.renderColor();
    layui.use(['form'], function (form) {
        var $ = layui.$;
        var index = parent.layer.getFrameIndex(window.name);
        var clipboard; // 复制对象

        // 获取URL参数
        var id = GetUrlParam("id");
        var tenantId = GetUrlParam("tenantId");

        // 构建邀请链接
        var baseUrl = window.location.origin;
        var inviteLink = baseUrl + "/tpl/tenant/joinTenant.html?id=" + id + "&tenantId=" + tenantId;

        // 设置链接到输入框
        $("#inviteLink").val(inviteLink);

        // 初始化复制功能
        clipboard = new ClipboardJS('#copyLink', {
            text: function () {
                return $("#inviteLink").val();
            }
        });

        clipboard.on('success', function (e) {
            winui.window.msg('复制成功', { icon: 1, time: 2000 });
        });

        clipboard.on('error', function (e) {
            winui.window.msg('浏览器不支持！', { icon: 2, time: 2000 });
        });

        // 关闭按钮点击事件
        $("body").on("click", "#cancle", function () {
            parent.layer.close(index);
        });

        matchingLanguage();
        form.render();
    });
});
